package com.example.combinedannotation;

import com.example.combinedannotation.config.DemoConfig;
import com.example.combinedannotation.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

@SpringBootApplication
public class CombinedAnnotationApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(CombinedAnnotationApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        //不适用 SpringBoot 默认加载，手动加载
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(DemoConfig.class);
        context.refresh();
        DemoService demoService = context.getBean(DemoService.class);
        demoService.output();
        context.close();
    }
}
